package com.greenant.store.utils;

import android.util.Log;

public class iLog
{
    private final static String TAG = "AntStoreTest";

    public static void d(String tag, String log) {

        final int invokeDepth = 1;
        if (isDebugAble()) {
            try {
                StackTraceElement[] stacks = new Throwable().getStackTrace();
                String className = stacks[invokeDepth].getClassName();
                className = className.substring(className.lastIndexOf(".") + 1);
                String methodName = stacks[invokeDepth].getMethodName();
                int lineNumber = stacks[invokeDepth].getLineNumber();
                StringBuffer sb = new StringBuffer();
                sb.append(className).append(" ").append(methodName).append(" ").append(lineNumber).append(" : ")
                        .append(log);

                Log.d(tag, sb.toString());
            } catch (Exception e) {
                Log.e(tag, log);
                e.printStackTrace();
            }
        }

    }

    public static void d(String log) {

        final int invokeDepth = 1;
        if (isDebugAble()) {
            try {
                StackTraceElement[] stacks = new Throwable().getStackTrace();
                String className = stacks[invokeDepth].getClassName();
                className = className.substring(className.lastIndexOf(".") + 1);
                String methodName = stacks[invokeDepth].getMethodName();
                int lineNumber = stacks[invokeDepth].getLineNumber();
                StringBuffer sb = new StringBuffer();
                sb.append(className).append(" ").append(methodName).append(" ").append(lineNumber).append(" : ")
                        .append(log);

                Log.d(TAG, sb.toString());
            } catch (Exception e) {
                Log.e(TAG, log);
                e.printStackTrace();
            }
        }

    }

    public static void e(String tag, String log) {

        final int invokeDepth = 1;
        if (isDebugAble()) {
            try {
                StackTraceElement[] stacks = new Throwable().getStackTrace();
                String className = stacks[invokeDepth].getClassName();
                className = className.substring(className.lastIndexOf(".") + 1);
                String methodName = stacks[invokeDepth].getMethodName();
                int lineNumber = stacks[invokeDepth].getLineNumber();
                StringBuffer sb = new StringBuffer();
                sb.append(className).append(" ").append(methodName).append(" ").append(lineNumber).append(" : ")
                        .append(log);

                Log.e(tag, sb.toString());
            } catch (Exception e) {
                Log.e(tag, log);
                e.printStackTrace();
            }
        }

    }

    public static void e(String tag, String log, Throwable th) {

        final int invokeDepth = 1;
        if (isDebugAble()) {
            try {
                StackTraceElement[] stacks = new Throwable().getStackTrace();
                String className = stacks[invokeDepth].getClassName();
                className = className.substring(className.lastIndexOf(".") + 1);
                String methodName = stacks[invokeDepth].getMethodName();
                int lineNumber = stacks[invokeDepth].getLineNumber();
                StringBuffer sb = new StringBuffer();
                sb.append(className).append(" ").append(methodName).append(" ").append(lineNumber).append(" : ")
                        .append(log);

                Log.e(tag, sb.toString(), th);
            } catch (Exception e) {
                Log.e(tag, log, th);
                e.printStackTrace();
            }
        }

    }

    public static void w(String tag, String log, Throwable e) {

        final int invokeDepth = 1;
        if (isDebugAble()) {
            try {
                StackTraceElement[] stacks = new Throwable().getStackTrace();
                String className = stacks[invokeDepth].getClassName();
                className = className.substring(className.lastIndexOf(".") + 1);
                String methodName = stacks[invokeDepth].getMethodName();
                int lineNumber = stacks[invokeDepth].getLineNumber();
                StringBuffer sb = new StringBuffer();
                sb.append(className).append(" ").append(methodName).append(" ").append(lineNumber).append(" : ")
                        .append(log);

                Log.w(tag, sb.toString(), e);
            } catch (Exception t) {
                Log.w(tag, log, t);
                t.printStackTrace();
            }
        }

    }

    public static void e(String log) {

        final int invokeDepth = 1;
        if (isDebugAble()) {
            try {
                StackTraceElement[] stacks = new Throwable().getStackTrace();
                String className = stacks[invokeDepth].getClassName();
                className = className.substring(className.lastIndexOf(".") + 1);
                String methodName = stacks[invokeDepth].getMethodName();
                int lineNumber = stacks[invokeDepth].getLineNumber();
                StringBuffer sb = new StringBuffer();
                sb.append(className).append(" ").append(methodName).append(" ").append(lineNumber).append(" : ")
                        .append(log);

                Log.e(TAG, sb.toString());
            } catch (Exception e) {
                Log.e(TAG, log);
                e.printStackTrace();
            }
        }

    }

    public static void i(String tag, String log) {

        final int invokeDepth = 1;
        if (isDebugAble()) {
            try {
                StackTraceElement[] stacks = new Throwable().getStackTrace();
                String className = stacks[invokeDepth].getClassName();
                className = className.substring(className.lastIndexOf(".") + 1);
                String methodName = stacks[invokeDepth].getMethodName();
                int lineNumber = stacks[invokeDepth].getLineNumber();
                StringBuffer sb = new StringBuffer();
                sb.append(className).append(" ").append(methodName).append(" ").append(lineNumber).append(" : ")
                        .append(log);

                Log.i(tag, sb.toString());
            } catch (Exception e) {
                Log.e(tag, log);
                e.printStackTrace();
            }
        }

    }

    public static void i(String log) {

        final int invokeDepth = 1;
        if (isDebugAble()) {
            try {
                StackTraceElement[] stacks = new Throwable().getStackTrace();
                String className = stacks[invokeDepth].getClassName();
                className = className.substring(className.lastIndexOf(".") + 1);
                String methodName = stacks[invokeDepth].getMethodName();
                int lineNumber = stacks[invokeDepth].getLineNumber();
                StringBuffer sb = new StringBuffer();
                sb.append(className).append(" ").append(methodName).append(" ").append(lineNumber).append(" : ")
                        .append(log);

                Log.i(TAG, sb.toString());
            } catch (Exception e) {
                Log.e(TAG, log);
                e.printStackTrace();
            }
        }

    }

    private static boolean isDebugAble() {

        // return Log.isLoggable(TAG, Log.DEBUG);
        // return false;
        return true;

    }


}
